<?php
/**
 * Hoffman Framework
 *
 * LICENSE
 *
 * This source file is subject to the GNU LGPL 2.1 license that is bundled
 * with this package in the file license.txt.
 * It is also available through the world-wide-web at this URL:
 * http://creativecommons.org/licenses/LGPL/2.1
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to annop@thaicyberpoint.com so we can send you a copy immediately.
 *
 * @package    Hoffman
 * @author     Ford AntiTrust
 * @copyright  Copyright (c) 2008 Ford AntiTrust (http://www.thaicyberpoint.com/ford/blog)
 * @since      Version Rv 0.2
 * @license    http://creativecommons.org/licenses/LGPL/2.1
 *             GNU LGPL 2.1
 * @filesource
 */

if (!defined('INDEX'))
    die('No direct script access allowed.');

/**
 * @see Zend_Registry
 */
require_once 'Zend/Registry.php';

/**
 * @see Zend_Locale
 */
require_once 'Zend/Locale.php';

/**
 * @see Hmf
 */
require_once 'Hmf.php';

/**
 * Hmf_Locale
 *
 *
 * @package     Hoffman
 * @subpackage  Hmf
 * @category    Locale
 * @author      Ford AntiTrust
 * @version     SVN: $Id: Locale.php 167 2010-02-18 10:32:16Z annop.s@gmail.com $
 * @link        http://www.thaicyberpoint.com/ford/blog/hmf
 */

class Hmf_Locale extends Hmf {

    private $locale;

    function __construct() {

        $this->setLocale(Zend_Registry::get('app_locale'));
    }

    final public static function createCoreInstanceLocale($locale) {

        return new Zend_Locale($locale);
    }

    final public static function isCoreInstanceLocale($locale) {

        return $locale instanceof Zend_Locale;
    }

    final public function setLocale($locale) {

        if (isset($this->locale) and self::isCoreInstanceLocale($this->locale) and self::isCoreInstanceLocale($locale)) {
            $this->locale = $locale;
        } else {
            $this->locale = self::createCoreInstanceLocale($locale);
        }
    }

    final public function getInstance() {

        if (!isset($this->locale)) {
            self::__construct();
        }
        return $this->locale;
    }

    final public function toString() {

        return $this->getInstance()->toString();
    }
}

?>
